//
//  NewLoanHeadView.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/11/9.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class NewLoanHeadView: UIView {

    var text : String! {
        didSet{
            titleLabel.text = text
        }
    }
    
    var isFlag : Bool! {
        didSet{
            loanButton.isHidden = isFlag
            lineView2.isHidden = isFlag
        }
    }
    
    fileprivate let titleLabel = UILabel()
    let moreButton = UIButton()
    let arrowButton = UIButton()
    let loanButton = UIButton()
    fileprivate let lineView2 = UIView()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        let redView = UIView()
        redView.backgroundColor = UIColor.red
        redView.layer.cornerRadius = RATIO(maxNum: 2)
        redView.layer.masksToBounds = true
        self.addSubview(redView)
        
        titleLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        self.addSubview(titleLabel)
        
        loanButton.setTitle(loanSelection, for: .normal)
        loanButton.setTitleColor(UIColor.red, for: .normal)
        loanButton.titleLabel?.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        self.addSubview(loanButton)
        
        lineView2.backgroundColor = UIColor.red
        self.addSubview(lineView2)
        
        moreButton.setTitle(more_title, for: .normal)
        moreButton.setTitleColor(UIColor.gray, for: .normal)
        moreButton.titleLabel?.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        self.addSubview(moreButton)
        
        arrowButton.layer.contents = #imageLiteral(resourceName: "next").cgImage
        self.addSubview(arrowButton)
        
        let lineView = UIView()
        lineView.backgroundColor = UIColor.lineColor()
        self.addSubview(lineView)
        
        redView.snp.makeConstraints { (make) in
            make.width.equalTo(RATIO(maxNum: 4))
            make.height.equalTo(RATIO_H(maxNum: 20))
            make.left.equalTo(RATIO(maxNum: 10))
            make.centerY.equalToSuperview()
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(redView.snp.right).offset(RATIO(maxNum: 10))
            make.centerY.equalToSuperview()
            make.width.greaterThanOrEqualTo(10)
            make.height.greaterThanOrEqualTo(10)
        }
        
        loanButton.snp.makeConstraints { (make) in
            make.left.equalTo(titleLabel.snp.right).offset(RATIO(maxNum: 20))
            make.centerY.equalTo(titleLabel)
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(RATIO_H(maxNum: 15))
        }
        
        lineView2.snp.makeConstraints { (make) in
            make.top.equalTo(loanButton.snp.bottom)
            make.centerX.width.equalTo(loanButton)
            make.height.equalTo(1)
        }
        
        arrowButton.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(RATIO(maxNum: -10))
            make.width.height.equalTo(RATIO_H(maxNum: 20))
            make.centerY.equalToSuperview()
        }
        
        moreButton.snp.makeConstraints { (make) in
            make.right.equalTo(arrowButton.snp.left)
            make.centerY.equalToSuperview()
            make.width.greaterThanOrEqualTo(10)
            make.height.greaterThanOrEqualTo(10)
            
        }
        
        lineView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
